package com.wunu.smartlock1.adapter;

import android.widget.ArrayAdapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.wunu.smartlock1.model.AuthorizedMemberVo;
import java.util.List;
import com.wunu.smartlock1.R;
/**
 * Created by admin on 2018/4/22.
 */

public class AuthorizedMemberAdapter extends ArrayAdapter {
    private int resourceId;
    public AuthorizedMemberAdapter(Context context, int textViewResourceId,List<AuthorizedMemberVo> list){
        super(context, textViewResourceId, list);
        resourceId = textViewResourceId;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AuthorizedMemberVo memberVo = (AuthorizedMemberVo) getItem(position); // 获取当前项的Fruit实例
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);//实例化一个对象 使用Inflater对象来将布局文件解析成一个View

        TextView authorizedType = (TextView) view.findViewById(R.id.authorizedType);//获取该布局内的文本视图
        TextView authorizedName = (TextView) view.findViewById(R.id.authorizedName);//获取该布局内的文本视图
        TextView authorizedDescript = (TextView) view.findViewById(R.id.authorizedDescript);//获取该布局内的文本视图
        TextView usedTimes = (TextView) view.findViewById(R.id.usedTimes);//获取该布局内的文本视图
        TextView leftTimes = (TextView) view.findViewById(R.id.leftTimes);//获取该布局内的文本视图
        ImageView authorizedPicUrl = (ImageView) view.findViewById(R.id.authorizedPicUrl);//获取该布局内的图片视图authorizedPicUrl
        ImageView menberPicUrl = (ImageView) view.findViewById(R.id.menberPicUrl);//获取该布局内的图片视图

        authorizedType.setText(memberVo.getAuthorizedType());//为文本视图设置文本内容
        authorizedName.setText(memberVo.getAuthorizedName());//为文本视图设置文本内容
        authorizedDescript.setText(memberVo.getAuthorizedDescript());//为文本视图设置文本内容
        authorizedPicUrl.setImageResource(memberVo.getAuthorizedPicUrl());//为图片视图设置图片资源

        //认证成员
        if(0 == memberVo.getMemberType()){
            menberPicUrl.setImageResource(memberVo.getMenberPicUrl());//为图片视图设置图片资源
        }else{//临时秘钥
            usedTimes.setText(""+memberVo.getUsedTimes());//为文本视图设置文本内容
            leftTimes.setText("余"+memberVo.getLeftTimes()+"次");//为文本视图设置文本内容
        }
        return view;
    }
}
